package com.tedu.ems_ssm.controller;

import com.tedu.ems_ssm.mapper.UserMapper;
import com.tedu.ems_ssm.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    UserMapper userMapper;

    @RequestMapping("/findAll")
    @CrossOrigin
    public List<User> selectAll(){
        List<User> userList=userMapper.selectUser();
        return userList;
    }

    @RequestMapping("/insert")
    @CrossOrigin
    public String insert(User user) {
        int a = userMapper.insert(user);
        if (a == 1) {
            return "插入成功";
        } else {
            return "插入失败";
        }
    }

    @RequestMapping("/delete")
    @CrossOrigin
    public void deleteByName(String name){
        userMapper.deleteByName(name);
        userMapper.delInc();
        userMapper.resetId();
        userMapper.openInc();
        //返回消息在html实现
    }

    @RequestMapping("/update")
    @CrossOrigin
    public void updateById(User user){
        userMapper.updateById(user);
        //返回html中实现
    }
}
